package com.zyw.zhuangdian.dao.impl;

import com.zyw.zhuangdian.dao.BaseDao;
import com.zyw.zhuangdian.dao.ReportDao;
import com.zyw.zhuangdian.exceptions.MyDaoException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Repository
@Transactional
public class ReportDaoImpl extends BaseDao implements ReportDao {
    @Override
    public void addReport(Map in) {
        int i = sqlTemplate.insert("ReportDaoImpl.addReport",in);
        if (i<1){
            throw new MyDaoException("插入投诉记录失败");
        }
    }

    @Override
    public void updateReport(Map in) {
        int i = sqlTemplate.update("ReportDaoImpl.updateReport",in);
        if (i<1){
            throw new MyDaoException("更新投诉记录失败");
        }
    }

    @Override
    public List<Map> listReports(Map in) {
        List<Map> list = sqlTemplate.selectList("ReportDaoImpl.listReports",in);
        return list;
    }

    @Override
    public int listReportsCount(Map in) {
        List<Map> list = sqlTemplate.selectList("ReportDaoImpl.listReportsCount",in);
        if (list.size() < 1){
            return 0;
        }
        return Integer.parseInt(list.get(0).get("count").toString());
    }
}
